﻿var app = new Vue({
	el: '#app',
	mixins: [page, isLogin],
	components: {
		navs: nav,
		footers: footer,
		login: login,
	},
	data: {
		bgImg: 'img/PCindex/top1.jpg',
		randomNum: 0, //验证码
		cityArr: ['全部', '广州', '韶关', '深圳', '珠海', '汕头', '佛山', '江门', '湛江', '茂名', '肇庆', '惠州', '梅州', '河源', '阳江', '清远', '东莞', '中山', '潮州', '汕尾', '揭阳', '云浮'], //城市数据
		//cityArr: ['全部', '广州', '韶关', '深圳', '珠海', '汕头', '佛山', '江门', '湛江', '茂名', '肇庆', '惠州', '梅州', '河源', '阳江', '清远', '东莞', '中山', '潮州', '汕尾', '揭阳', '云浮', '珠三角', '粤东', '粤西', '粤北', '外省', '港澳'],//城市数据
		buildClassArr: ['全部', '勘察招标', '设计招标', '监理招标', '施工招标', '材料设备招标', '其他招标'], //招标分类数组
		inputRandomNum: '', //用户输入的验证码
		searchContent: '', //搜索内容
		buildClass: '全部', //招标分类
		city: '全部', //城市
		initData: '', //初始化数据
		navState: '招标资讯',
	},
	watch: {
		buildClass: function() {
			this.totalPage = '';
		},
		city: function() {
			this.totalPage = '';
		},
		searchContent: function() {
			this.totalPage = '';
		},
	},
	methods: {
		//header组件的搜索方法
		searchHeader: function(searchCtx) {

		},
		//随机生成4位数
		randomFourNum: function() {
			this.randomNum = xq.rand(1000, 9999);
		},
		//		//一进来获取最新招标信息
		initDataFuc: function() {
			var _this = this;
			var method = 'Tender/GetTenderTitle';
			var param = {
				PageSize: 12
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					if(!_this.totalPage) {
						_this.totalPage = Math.ceil(res.data.TotalCount / _this.onePageCount);
						_this.initPage();
					}
					_this.initData = res.data;
				} else {
					_this.initData = [];
				}
			})
		},
		//帅选获取数据
		getNewsList: function(currentPage) {
			var _this = this;
			var city = '';
			var buildClass = '';
			this.onePageCount = 12;
			if(this.city != '全部') {
				city = this.city;
			}
			if(this.buildClass != '全部') {
				buildClass = this.buildClass;
			}
			if(currentPage) {
				currentPage = currentPage
			} else {
				currentPage = 1;
			}
			var method = 'Tender/GetSearchInfo';

			var param = {
				Keyword: this.searchContent,
				ColumnID: buildClass,
				ListCount: this.onePageCount,
				PageIndex: currentPage,
				Area: city,
			};
			xq.getUrl(method, param, function(res) {
				if(res.data.ListEntity.length > 0) {
					if(!_this.totalPage) {
						_this.pageArr = [];
						_this.totalPage = Math.ceil(res.data.TotalCount / _this.onePageCount);
						_this.initPage();
					}
					_this.initData = res.data.ListEntity;
				} else {
					_this.initData = '';
				}

			});
		},
		//搜索按钮
		search: function() {
			var _this = this;
			if(this.inputRandomNum == this.randomNum) {
				this.getNewsList();
				this.randomFourNum();
				//				this.searchContent = '';
			} else {
				xq.toast1('请输入验证码');
			}
		},
		//切换城市更换city数据
		tapCity: function(city) {
			this.city = city;
			this.currentPage = 1;
			this.getNewsList();
		},
		//切换招标分类更换buildClass数据
		tapBuildClass: function(buildClass) {
			this.buildClass = buildClass;
			this.currentPage = 1;
			this.getNewsList();
		},
		//跳转招标信息详情页
		tobids: function(bid) {
			var Url = 'bids.html?id=' + bid;
			window.open(Url, '_blank');
		},
		//初始化脚本
		initScript: function() {
			var ot = $(".newCtxNav ul").offset().top;
			$(document).scroll(function() {
				if(ot - $(document).scrollTop() - 20 <= 0) {
					$(".newCtxNav ul").css({
						"position": "fixed",
						"top": 20
					})
				} else {
					$(".newCtxNav ul").css({
						"position": "static",
						"top": 0
					})
				}

			})
			$(".classSelectBtn").click(function() {
				if($(this).attr("data-type") == 0) {
					$(this).attr("data-type", 1).html("显示筛选&nbsp;&uArr;")
					$(".classSelect").show();
				} else {
					$(this).attr("data-type", 0).html("显示筛选&nbsp;&dArr;")
					$(".classSelect").hide();
				}
			})
			var swiper = new Swiper('.swiper-container', {
				pagination: '.swiper-pagination',
				autoplay: 3000,
				autoplayDisableOnInteraction: false,
			});
		},
	},
	mounted: function() {
		this.getNewsList();
		this.randomFourNum();
		this.initScript();
		//		xq.confitAnimate();
	},
	updated: function() {

	}
})